package com.hogofwar.DJbot;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;


public class PluginLoad {


public static BasePlugin getPlugin(String classname) {
	URL[] urls = null;
	BasePlugin plugin = null;
	try {
	    // Convert the file object to a URL
	    File dir = new File("plugins/bin/");
	    URL url = dir.toURL();        // file:/c:/almanac1.4/examples/
	    urls = new URL[]{url};
	} catch (MalformedURLException e) {
	}


	    try {
			// Create a new class loader with the directory
			ClassLoader cl = new URLClassLoader(urls);

			// Load in the class
			Class cls = cl.loadClass(classname);

			// Create a new instance of the new class
			 plugin = (BasePlugin)cls.newInstance();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	   

	 
	return plugin;
}
}
